import os
from celery import Celery
from django.conf import settings
from iClouds import celerycfg

# 设置django环境
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "iClouds.settings")

# 创建celery app
app = Celery("iClouds")

#  使用CELERY_ 作为前缀，在settings中写配置
# app.config_from_object("django.conf.settings", namespace="CELERY")
app.config_from_object(celerycfg)

# 发现任务文件每个app下的task.py
# app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
app.autodiscover_tasks()

# 调用异步任务,返回任务ID
# res=MyCeleryTest.delay(3,4)
# res=MyCeleryTest.apply_async(args=[3,4])
# res=MyCeleryTest.apply_async(kwds={'a':4,'b':4})
